package com.dididoctor.patient.Activity.DiagnosisDetails;

import android.content.Context;

import com.dididoctor.patient.Activity.ConstantValue;
import com.dididoctor.patient.Bean.Token;
import com.dididoctor.patient.Http.MyHttpResponseHandler;
import com.dididoctor.patient.MV.BasePresenter;
import com.dididoctor.patient.MV.BusinessClient;
import com.dididoctor.patient.MV.Response;
import com.dididoctor.patient.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称：
 * @包名称：
 * @创建人：李营
 * @创建时间：2016/4/27 16:40
 * @修改人：
 * @修改时间：2016/4/27 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class DiagnosisDetailsPresenter extends BasePresenter {
    private DiagnosisDetailsView view;

    public DiagnosisDetailsPresenter(Context context, DiagnosisDetailsView view) {
        super(context, view);
        this.view = view;
    }

    public void getInquiryDetails(String recId) {
        RequestParams params = new RequestParams();
//        userId	String	是	用户
//        token	String	是
//        recId	String	String	病历id
//        qryType	String	是	定值 1 （医生端）
        params.put("userId", Token.getId());
        params.put("token", Token.getToken());
        params.put("recId", recId);

        BusinessClient.post(ConstantValue.medicaldetail, params, new MyHttpResponseHandler() {
            private String result = "";
            private ArrayList<DiagnosisDetailsBean> datas = new ArrayList<DiagnosisDetailsBean>();
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    result = response.getString("result");
                    maps = response.getListData("advices");
                    for (Map<String, String> map : maps) {
                        DiagnosisDetailsBean bean = new DiagnosisDetailsBean();
                        bean.setType(Util.toString(map.get("type")));
                        bean.setContent(Util.toString(map.get("content")));
                        datas.add(bean);
                    }
                    view.fillData(datas, result);
                } else {
                    view.showToastMessage(response.getMsg());
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getDataFail();
            }
        });
    }
}
